﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class Player : Object2D
    {

        TiroManager tiros;

        public Player() : base() { }

        public Player(Texture2D texture)
            : base(texture)
        {
            
        }
        public Player(Rectangle rect)
            : base()
        {
        }
        public Player(Texture2D texture, Vector2 position)
            : base(texture, position)
        {
        }
        public Player(Texture2D texture , Rectangle rect)
            : base(texture , rect)
        {
            
        }

        public override void Load(ContentManager Content)
        {
            base.Load(Content);
            
            tiros = new TiroManager();
            tiros.Load(Content);

            Texture = Content.Load<Texture2D>("nave");

            Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);
            SourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
        }

        public void Update(GameTime gameTime)
        {

            if (Input.KeyPressed(Keys.D))
            {
                Position = new Vector2(Position.X + 1, Position.Y);

            }
            else if (Input.KeyPressed(Keys.A))
            {
                Position -= new Vector2(1, 0);
            }

            if (Input.KeyPressed(Keys.W))
            {
                Position -= new Vector2(0, 1);
            }
            else if (Input.KeyPressed(Keys.S))
            {
                Position += new Vector2(0, 1);
            }

            if (Input.KeyDown(Keys.Space))
            {
                tiros.AddShot(new Vector2(Position.X - Texture.Width / 2, Position.Y));
            }

            tiros.Update();
            
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            tiros.Draw(spriteBatch);
            base.Draw(spriteBatch); 
            
        }

    }
}
